package eai.tp2.lpco.credentials.register;

import javax.ejb.Stateful;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import eai.tp2.lpco.credentials.auth.IAuthentication;
import eai.tp2.lpco.database.User;

/**
 * Session Bean implementation class CredentialsManager
 */
@Stateless
public class RegisterBean implements IRegistry {

	@PersistenceContext(unitName = "myLpcoCatalogue")
	private EntityManager em;

	/**
	 * Default constructor.
	 */
	public RegisterBean() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean saveUserInfo(User user) {
		User temp = null;
		if ((temp = em.find(User.class, user.getUsername())) == null) {
			em.persist(user);
			em.flush();
			return true;
		}
		return false;
	}

}
